<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <!-- <el-form-item>
          <el-input v-model="filters.username" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="filters.userid" placeholder="用户ID"></el-input>
        </el-form-item> -->
        <el-form-item>
          <el-button size="small" type="primary" icon="search" v-on:click="getcustoms">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="warning" icon="plus" @click="handleAdd">新增</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="upload2" @click="export2Excel">导出</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="users" stripe border :height="winHeight-210"  highlight-current-row v-loading="listLoading" @selection-change="selsChange" @cell-click="dblclick" style="width: 100%;">
      <!-- <el-table-column type="selection" width="55">
      </el-table-column> -->
      <!-- <el-table-column prop="serialNo" label="序号" width="120" sortable>
      </el-table-column> -->

      <!-- <el-table-column prop="userid" label="用户ID" width="160" sortable>
          <template scope="scope">
            <span style="color:#20a0ff;cursor:pointer;text-decoration:underline;">{{scope.row.userid}}</span>
          </template>
      </el-table-column> -->
      <el-table-column prop="username" label="服务器名称" width="150">
      </el-table-column>
      <el-table-column prop="sex" label="用户名"  width="150" sortable>
      </el-table-column>
      <el-table-column prop="phoneno" label="密码" min-width="180"  sortable>
      </el-table-column>
      <el-table-column prop="mobileno" label="IP" min-width="180" sortable>
      </el-table-column>
      <el-table-column prop="email" label="端口号" width="180" sortable>
      </el-table-column>

      <el-table-column prop="url" label="地址" min-width="120" sortable>
      </el-table-column>
      <el-table-column prop="userid" label="存储路径" min-width="120" sortable>
      </el-table-column>
      <el-table-column prop="status" label="状态" min-width="120" :formatter="formatStatus" sortable>
      </el-table-column>
      <el-table-column label="操作" fixed='right' width="180">
        <template scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button type="primary" size="small" v-show="buttonShows(scope.$index, scope.row)"  @click="handleRecover(scope.$index, scope.row)">恢复</el-button>
          <el-button type="danger" size="small" v-show="buttonShow(scope.$index, scope.row)"
           @click="handleDel(scope.$index, scope.row)">失效</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->

      <el-pagination style="float:right" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[10, 20, 40, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-col>


    <!--详情-->
    <el-dialog title="详情"  v-model="detailFormVisible" :close-on-click-modal="false">
      <el-form :model="detailForm"  label-width="120px" :rules="detailFormRules" ref="detailForm">
            <el-row :gutter="20">
                 <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="用户ID">
                  <el-input v-model="detailForm.userid" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="用户名">
                  <el-input v-model="detailForm.username" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="机构">
                  <el-input v-model="detailForm.branchcode" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="小组">
                  <el-input v-model="detailForm.termcode" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="用户级别">
                  <el-input v-model="detailForm.clevel" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="性别">
                  <el-input v-model="detailForm.sex" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
               <el-form-item label="电话">
                  <el-input v-model="detailForm.phoneno" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="手机">
                  <el-input v-model="detailForm.mobileno" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="邮箱">
                  <el-input v-model="detailForm.email" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="登陆次数">
                  <el-input v-model="detailForm.loginnum" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="最近登陆时间">
                  <el-input v-model="detailForm.lastlogindate" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="退出时间">
                  <el-input v-model="detailForm.logoutdate" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="登陆IP">
                  <el-input v-model="detailForm.loginip" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="备注">
                  <el-input v-model="detailForm.remarks" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
               <el-form-item label="创建日期">
                  <el-input v-model="detailForm.created" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="创建人">
                  <el-input v-model="detailForm.creater" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="授权类型">
                  <el-input v-model="detailForm.authtype" :readonly="true" auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="注销日期">
                  <el-input v-model="detailForm.disableddate" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="状态">
                  <el-select :span="24"  v-model="detailForm.status" :readonly="true" >
                      <el-option label="有效"  value="0"  ></el-option>
                      <el-option label="无效"  value="1"  ></el-option>
                  </el-select>
              </el-form-item>
               </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="授权级别">
                  <el-input v-model="detailForm.authLevel" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
               </el-col>
              </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="detailFormVisible = false">取消</el-button>
        <!-- <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button> -->
      </div>
    </el-dialog>

    <!--新增界面-->
    <el-dialog title="新增"  v-model="addFormVisible" :close-on-click-modal="false">
      <el-form  label-width="120px" :model="addForm" :rules="addFormRules"    ref="addForm">
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
                  <el-form-item label="用户ID" prop="userid">
                      <el-input v-model="addForm.userid" auto-complete="off" >
                        <el-button slot="append" @click="inquiry" icon="search"></el-button>
                      </el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
                  <el-form-item label="授权级别" prop="name">
                      <el-input v-model="addForm.authLevel" auto-complete="off" >
                      </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="用户名" prop="username">
                  <el-input v-model="addForm.username" :readonly='true' auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="机构">
                  <el-input v-model="addForm.branchcode"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
              <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="小组">
                <el-input v-model="addForm.termcode"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="用户级别">
                  <el-input v-model="addForm.clevel"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="性别">
                  <el-input v-model="addForm.sex"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
               <el-form-item label="电话">
                  <el-input v-model="addForm.phoneno"   auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="手机">
                  <el-input v-model="addForm.mobileno"   auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="邮箱">
                  <el-input v-model="addForm.email"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="登陆次数" v-show="IsShow">
                  <el-input v-model="addForm.loginnum"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="最近登陆时间" v-show="IsShow">
                  <el-input v-model="addForm.lastlogindate"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="退出时间" v-show="IsShow">
                  <el-input v-model="addForm.logoutdate"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="登陆IP" v-show="IsShow">
                  <el-input v-model="addForm.loginip"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="创建日期" v-show="IsShow">
                  <el-input v-model="addForm.created"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="注销日期" v-show="IsShow">
                  <el-input v-model="addForm.disableddate"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="创建人" >
                  <el-input v-model="addForm.creater"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="授权类型" >
                  <el-input v-model="addForm.authtype"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                  <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="状态">
                  <el-select :span="24"  v-model="addForm.status" placeholder="请选择">
                      <el-option label="有效"  value="0"  ></el-option>
                      <el-option label="无效"  value="1"  ></el-option>
                  </el-select>
              </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="20" :md="16" :lg="11">
              <el-form-item label="备注">
                  <el-input v-model="addForm.remarks"  auto-complete="off"></el-input>
              </el-form-item>
              </el-col>
              </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
      </div>
    </el-dialog>


     <!-- 修改 -->
     <el-dialog title="设置权限"  v-model="editFormVisible"  :close-on-click-modal="false">
        <el-form :model="editForm"  label-width="":inline="true" style="text-align:center;" :rules="editFormRules"   ref="editForm">
             <!--<el-form-item style="padding:10px;">
                  <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
                    <el-checkbox v-for="role in roles" :label="role.id">{{role.label}}</el-checkbox>
                  </el-checkbox-group>
              </el-form-item> -->

              <el-form-item label="角色" prop="riskCode">
                  <el-select v-model="editForm.id"   placeholder="角色">
                    <el-option v-for="role in roles" :key="item.id" :label="role.label" :value="role.id"  ></el-option>
                  </el-select>
              </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click.native="editFormVisible = false">取消</el-button>
            <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
        </div>
     </el-dialog>

  </section>
</template>

<script>
  import util from '../../common/js/util'

  import commons from '../../common/js/common'
  //import NProgress from 'nprogress'
  import { mapState, mapActions } from 'vuex'
  import {adminList,addAdmin,LdapUser,roleList,getRoleOfUser,updateAdminStauts} from '../../api/api';
  export default {
    data() {
      return {
        checkedCities: ['上海', '北京'],
        roles:[],

        filters: {
         username:'',
         userid:''
        },
        users: [],
        lists:[],
        total: 0,
        page: 1,
        pageSize:10,
        listLoading: false,
        sels: [],//列表选中列
        userid:'',
        addFormVisible:false,//新增界面是否显示
        editFormVisible: false,//修改界面是否显示
        editLoading: false,
        addFormRules:{
          userid: [
            { required: true, message: '请输入用户ID并查询', trigger: 'blur' }
          ],
          username: [
            { required: true, message: '请查询用户ID', trigger: 'blur' }
          ]
        },
        editFormRules: {
          // name: [
          //   { required: true, message: '请输入姓名', trigger: 'blur' }
          // ]
        },
        //修改界面数据
        editForm: {
          id:'',
        },
        detailFormVisible: false,//新增界面是否显示
        addLoading: false,
        IsShow:false,
        detailFormRules: {
          // name: [
          //   { required: true, message: '请输入姓名', trigger: 'blur' }
          // ]
        },
        //新增界面数据
        addForm:{
            userid:'',
            username:'',
            password:'',
            branchcode:'',
            deptcode:'',
            termcode:'',
            clevel:'',
            sex:'',
            phoneno:'',
            mobileno:'',
            email:'',
            loginnum:'',
            lastlogindate:'',
            logoutdate:'',
            loginip:'',
            remarks:'',
            created:'',
            creater:'',
            authtype:'',
            disableddate:'',
            status:'',
            authLevel:''
        },
        //详情界面数据
        detailForm:{
            userid:'',
            username:'',
            password:'',
            branchcode:'',
            deptcode:'',
            termcode:'',
            clevel:'',
            sex:'',
            phoneno:'',
            mobileno:'',
            email:'',
            loginnum:'',
            lastlogindate:'',
            logoutdate:'',
            loginip:'',
            remarks:'',
            created:'',
            creater:'',
            authtype:'',
            disableddate:'',
            status:'',
            authLevel:''
        }

      }
    },
    computed: mapState([
      'winWidth',
      'winHeight'
      ]),
    methods: {
      formatStatus :function(row, column){
        return row.status == '1' ? '有效' : (row.status == '0' ? '无效' : '');
      },
      buttonShow(index,row){
        return row.status=="1"? true: false;
      },
      buttonShows(index,row){
        return row.status=="0"? true: false;
      },
      handleCheckedCitiesChange(value) {
        let checkedCount = value.length;
        this.checkAll = checkedCount === this.cities.length;
        this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
      },
      inquiry(){
        let para = new FormData();
        para.append("userId",this.addForm.userid);
        LdapUser(para).then((res) => {
          if(res.data.state==0){
            this.addForm.username = res.data.result.username;
            this.addForm.mobileno = res.data.result.mobileno;
            this.addForm.phoneno = res.data.result.phoneno;
            this.addForm.branchcode = res.data.result.branchcode;
            this.addForm.deptcode = res.data.result.deptcode;
            this.addForm.email = res.data.result.email;
            this.addForm.sex = res.data.result.sex;
            this.addForm.clevel = res.data.result.clevel;
            this.addForm.termcode = res.data.result.termcode;
            this.addForm.remarks = res.data.result.remarks;
          }
          else{
              this.$message({
                message: '未查到该用户的相关信息',
                type: 'error'
              })
          }
        });

      },
      handleCurrentChange(val) {
        this.page = val;
        this.getcustoms();
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.getcustoms();
      },
      //获取用户列表
      getcustoms() {
        // let para = {
        //   pageSize: 10,
        //   pageNumber: this.page,
        //   productCname:'',
        //   riskCode:'',
        //   startDate:'',
        //   endDate:''
        // };
        let para = new FormData();
        let role = new FormData();
        para.append("pageSize",this.pageSize);
        para.append("pageNumber",this.page);
        para.append("username",this.filters.username);
        para.append("userid",this.filters.userid);
        this.listLoading = true;
        //NProgress.start();
        adminList(para).then((res) => {
        this.total = res.data.result.totalElements;
        this.users = res.data.result.content;
        this.lists = res.data.result.content;
        this.listLoading = false;
        //NProgress.done();
        });

        role.append("pageSize",100);
        role.append("pageNumber",this.page);
        role.append('type','');
        roleList(role).then((res) => {
          var data = res.data.result.content;
          if(data){
            for(var i in data){
                this.roles.push({
                  id: data[i].roleid,
                  label: data[i].rolename
                });
            }
          }
          // _this.roles = res.data.result.content;
        });
      },
      //详情
      dblclick(row, column, cell, event){
        if(column.label=='用户ID'){
            this.detailFormVisible = true;
            this.detailForm = row;
            this.detailForm.lastlogindate = commons.getDaytime(row.lastlogindate,1);
            this.detailForm.logoutdate = commons.getDaytime(row.logoutdate,1);
            this.detailForm.created = commons.getDaytime(row.created,1);
            this.detailForm.disableddate = commons.getDaytime(row.disableddate,1);
            this.detailForm.status = commons.userStaus(row.status);
            this.rowID = row.id;
        }
      },
      //恢复
      handleRecover: function (index, row) {
        this.$confirm('确认恢复该记录吗?', '提示', {
          type: 'warning'
        }).then(() => {
          this.listLoading = true;
          let para = new FormData();
          para.append("userid", row.userid);
          para.append("type", "1");
          updateAdminStauts(para).then((res) => {
            this.listLoading = false;
            this.$message({
              message: '恢复成功',
              type: 'success'
            });
            this.getcustoms();
          });
        }).catch(() => {

        });
      },
      //删除
      handleDel: function (index, row) {
        this.$confirm('确认失效该记录吗?', '提示', {
          type: 'warning'
        }).then(() => {
          this.listLoading = true;
          let para = new FormData();
          para.append("userid", row.userid);
          para.append("type", "0");
          updateAdminStauts(para).then((res) => {
            this.listLoading = false;
            //NProgress.done();
            this.$message({
              message: '失效成功',
              type: 'success'
            });
            this.getcustoms();
          });
        }).catch(() => {

        });
      },

      //table导出excel
      export2Excel: function() {
　　　　　　require.ensure([], () => {
　　　　　　　　const { export_json_to_excel } = require('../../vendor/Export2Excel');
　　　　　　　　const tHeader = ['用户ID', '用户名', '密码', '机构', '部门', '小组','用户级别','性别','电话','手机','邮箱','登陆次数','最近登陆时间','退出时间','登陆IP','备注','创建日期','创建人','授权类型','注销日期','状态','授权级别'];
　　　　　　　　const filterVal = [ 'userid', 'username', 'password', 'branchcode', 'deptcode', 'termcode', 'clevel', 'sex', 'phoneno', 'mobileno', 'email', 'loginnum', 'lastlogindate', 'logoutdate', 'loginip', 'remarks', 'created', 'creater', 'authtype', 'disableddate', 'status', 'authLevel'];
　　　　　　　　const list = this.lists;
　　　　　　　　const data = this.formatJson(filterVal, list);
　　　　　　　　export_json_to_excel(tHeader, data, '用户列表excel');
　　　　　　})
　　　　},
　　　formatJson:function(filterVal, jsonData) {
　　　　　　return jsonData.map(v => filterVal.map(j => v[j]))
　　　},

      //显示修改界面
      handleEdit: function (index, row) {
        this.editFormVisible = true;
        // this.editForm = Object.assign({}, row);
        let para = new FormData();
        para.append('userId',row.userid);
        getRoleOfUser(para).then((res) => {
          this.editForm.id =  res.data.result.roleid;
        });
      },
      //显示新增界面
      handleAdd: function () {
        this.addFormVisible = true;
        this.addForm={
            userid:'',
            username:'',
            password:'',
            branchcode:'',
            deptcode:'',
            termcode:'',
            clevel:'',
            sex:'',
            phoneno:'',
            mobileno:'',
            email:'',
            loginnum:'',
            lastlogindate:'',
            logoutdate:'',
            loginip:'',
            remarks:'',
            created:'',
            creater:'',
            authtype:'',
            disableddate:'',
            status:'',
            authLevel:''
        };
        this.addForm.status= '0';
       // this.detailForm = {
        //   // id: '',
        //   adType: '',
        //   imgUrl: '',
        //   toUrl:'',
        //   toType:'',
        //   isShow:'',
        //   description:'',
        //   remark:''
        // };
      },
      //新增提交
      addSubmit: function(){
          this.$refs.addForm.validate((valid) => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {}).then(() => {
              this.addLoading = true;
              //NProgress.start();
              let para = Object.assign({}, this.addForm);
              addAdmin(para).then((res) => {
                  if(res.data.state == 1){
                    this.$message({
                      message: '该用户已经存在！',
                      type: 'error'
                    })
                  }
                  else{
                      this.addLoading = false;
                      //NProgress.done();
                      this.$message({
                        message: '提交成功',
                        type: 'success'
                      });
                      this.$refs['addForm'].resetFields();
                      this.addFormVisible = false;
                      this.getcustoms();
                  }


              });
            });
          }
        });
      },
      //修改
      editSubmit: function () {
        this.$refs.editForm.validate((valid) => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {}).then(() => {
              this.editLoading = true;
              //NProgress.start();
              let para = Object.assign({}, this.editForm);
              para.startDate = (!para.startDate || para.startDate == '') ? '' : util.formatDate.format(new Date(para.startDate), 'yyyy-MM-dd');
              para.endDate = (!para.endDate || para.endDate == '') ? '' : util.formatDate.format(new Date(para.endDate), 'yyyy-MM-dd');
              editAd(para).then((res) => {
                this.editLoading = false;
                //NProgress.done();
                this.$message({
                  message: '提交成功',
                  type: 'success'
                });
                this.$refs['editForm'].resetFields();
                this.editFormVisible = false;
                this.getcustoms();
              });
            });
          }
        });
      },

      selsChange: function (sels) {
        this.sels = sels;
      },
      //批量删除
      batchRemove: function () {
        var ids = this.sels.map(item => item.id).toString();
        this.$confirm('确认删除选中记录吗？', '提示', {
          type: 'warning'
        }).then(() => {
          this.listLoading = true;
          //NProgress.start();
          // let para = { ids: ids };
          let para = new FormData();
          para.append("ids", ids);
          removeAd(para).then((res) => {
            this.listLoading = false;
            //NProgress.done();
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getcustoms();
          });
        }).catch(() => {

        });
      }
    },
    mounted() {
      // this.getcustoms();
    }
  }

</script>

<style scoped>

</style>